package demo_0427.homework1;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class T2_0427 {
    /*2.读入一个文本文件（Cinderella.txt），统计每个字母出现的次数（HashMap）*/
    public static void main(String[] args) {
        Map<Character,Integer> map = new HashMap<>();
        String text = "resource/Cinderella.txt";
        try {
            BufferedReader reader = new BufferedReader(new FileReader(text));
            String line;
            while ((line = reader.readLine())!=null) {
                for (char c : line.toCharArray()) {
                    if (Character.isLetter(c)) {
                        map.put(c, map.getOrDefault(c, 0) + 1);
                    }
                }
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        System.out.println(map);
    }
}
